package com.example.controller;

import com.example.pojo.Question;
import com.example.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/questions")
public class QuestionController {
    // 控制器类，处理与问题相关的请求
    @Autowired
    private QuestionService questionService;

    // 获取所有问题的列表
    @GetMapping
    public List<Question> getAllQuestions() {
        return questionService.getAllQuestions();
    }

    // 根据ID获取特定问题
    @GetMapping("/{id}")
    public Question getQuestion(@PathVariable Integer id) {
        return questionService.getQuestionById(id);
    }

    // 创建新的问题
    @PostMapping
    public void createQuestion(@RequestBody Question question) {
        questionService.saveQuestion(question);
    }

    // 检查答案是否正确
    @PostMapping("/{id}/check")
    public boolean checkAnswer(@PathVariable Integer id, @RequestParam Integer answerIndex) {
        return questionService.checkAnswer(id, answerIndex);
    }
}
